package cn.com.utt.common.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.com.utt.common.mapper.CustomColumnMapper;
import cn.com.utt.common.service.TableService;
import cn.com.utt.common.vo.CustomColumn;
import cn.com.utt.common.vo.OrderColumn;
import cn.com.utt.common.vo.TableCustomColumn;

@Service("tableService")
public class TableServiceImpl implements TableService {
	
	@Autowired
	private CustomColumnMapper customColumnMapper;

	@Override
	public List<CustomColumn> queryCustomColumnByTable(String tableName, Long userId) {
		return customColumnMapper.queryByTable(tableName, userId);
	}

	@Override
	public void updateCustomColumn(TableCustomColumn customColumn, Long userId) {
		customColumnMapper.deleteAll(customColumn.getTableName(), userId);
		for (OrderColumn column : customColumn.getColumns()) {
			CustomColumn col = new CustomColumn();
			col.setTableName(customColumn.getTableName());
			col.setUserId(userId);
			col.setColumn(column.getColumn());
			col.setOrder(column.getOrder());
			customColumnMapper.save(col);
		}
	}
}
